import 'package:exsun_plate_app/mvp/presenter/login_presenter.dart';
import 'package:exsun_plate_app/mvp/repository/login_repository_iml.dart';

class LoginPresenterIml implements LoginPresenter {
  LoginRepositoryIml _loginRepositoryIml;

  LoginView _loginView;


  LoginPresenterIml(this._loginView){
    assert(_loginView!=null);
    _loginView.setPresenter(this);
  }

  @override
  init() {
    _loginRepositoryIml = LoginRepositoryIml();
  }

  @override
  login(String userName, String password) {
    _loginRepositoryIml.fetch(userName, password).then((data){
      _loginView.onLoginSuccess(data);
    }).catchError((error){
      print(error);
      _loginView.onLoginFail(error.toString());
    });

  }

  @override
  getCode(String phone) {
    _loginRepositoryIml.getCode(phone).then((data){
      _loginView.onCodeSuccess(data);
    }).catchError((error){
      print(error);
      _loginView.onCodeFail(error.toString());
    });
  }
}
